package com.yanqu.road.server.manager.activity.suitang.task.impl;

import com.yanqu.road.entity.activity.suitang.data.CrossSuiTangCity;
import com.yanqu.road.entity.activity.suitang.data.CrossSuiTangData;
import com.yanqu.road.entity.activity.suitang.enums.eSuiTangWarType;
import com.yanqu.road.entity.activity.suitang.enums.eSuiTangStage;
import com.yanqu.road.server.manager.activity.suitang.activity.CrossSuiTangActivity;
import com.yanqu.road.utils.executor.GeneralTask;

import java.util.Map;

public class CrossSuiTangCityTask extends GeneralTask {

    private CrossSuiTangActivity activity;
    private int taskNo = 0;

    public CrossSuiTangCityTask(CrossSuiTangActivity activity, int taskNo) {
        this.activity = activity;
        this.taskNo = taskNo;
    }

    @Override
    public void doRun() {
        if (activity.getCrossSuiTangData().getStep().getValue() > eSuiTangStage.WaitRewardTime.getValue()) {
            this.cancel(false);
            return;
        }
        CrossSuiTangData crossSuiTangData = activity.getCrossSuiTangData();
        if (crossSuiTangData == null) {
            return;
        }
        Map<eSuiTangWarType, Map<Integer, Map<Integer, CrossSuiTangCity>>> roundMap = crossSuiTangData.getCityMap().get(activity.calcRound());
        if (roundMap == null || roundMap.isEmpty()) {
            return;
        }

        for (Map<Integer, Map<Integer, CrossSuiTangCity>> warTypeMap : roundMap.values()) {
            for (Map<Integer, CrossSuiTangCity> actGroupMap : warTypeMap.values()) {
                for (CrossSuiTangCity city : actGroupMap.values()) {
                    if (city == null) {
                        continue;
                    }
                    if (city.getCityId() % activity.getTaskNum() != taskNo) {
                        continue;
                    }
                    activity.getBattleActivityMgr().crossSuiTangCityTask(city.getCityId(), city.getWarType(), city.getActGroupId());
                }
            }
        }
    }
}
